<template>
  <div style="padding-bottom: 100px">
    <el-row>
      <el-button
        icon="el-icon-circle-plus-outline"
        type="primary"
        plain
        size="medium"
        @click="onAdd()"
        :disabled="!zIsOpenData"
        >增加角色</el-button
      >
      <el-button
        icon="el-icon-refresh"
        type="primary"
        plain
        size="medium"
        @click="openData()"
        >刷新数据</el-button
      >
      <el-button
        icon="el-icon-refresh"
        type="primary"
        plain
        size="medium"
        @click="initRoleRight()"
        >刷新中间件角色信息</el-button
      >
      <el-dialog v-model="FIsShowRole" width="400PX" center destroy-on-close>
        <TFormRoleEdit
          :zContextParams="contextParams"
          :zContextOnCall="onCallBack"
        ></TFormRoleEdit>
      </el-dialog>
    </el-row>
    <el-table
      :data="FRoleList"
      style="width: 100%; margin-top: 10px; margin-bottom: 20px"
      row-key="FRoleID"
      border
      default-expand-all
      highlight-current-row
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="FRoleName" label="角色名称"> </el-table-column>
      <el-table-column prop="FTreeCode" label="树形代码"> </el-table-column>
      <el-table-column prop="FStatusCode" label="状态"> </el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button
            type="primary"
            plain
            size="mini"
            @click="onEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            type="warning"
            plain
            size="mini"
            @click="onRightEdit(scope.$index, scope.row)"
            >权限设定</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script lang="ts">
import { Options, Vue } from "vue-class-component";
import TFormBase from "@/views/BaseForm";
import { TBaseRole } from "@/baselib/right/BaseRightClass";
import TFormRoleEdit from "./RoleEdit.vue";
import { IMenuItem } from "@/store";
//配合着用
@Options({
  name: "TFormRoleList",
  components: {
    TFormRoleEdit,
  },
  computed: {},
  data() {},
})
export default class TFormRoleList extends TFormBase {
  private FIsShowRole: boolean = false;
  private FIndexRole: TBaseRole = new TBaseRole();
  private FRoleList: TBaseRole[] = [];
  private get contextParams() {
    return { IndexRole: this.FIndexRole, RoleList: this.FRoleList };
  }
  public created() {
    this.openData();
  }
  //打开数据
  public async openData() {
    this.zIsOpenData = false;
    let lResult = await this.$myBaseRightAPI.getRoleList();
    if (!lResult.resultSuccess) {
      this.$myMsgHelp.msgDialog(lResult.resultMsg);
      return;
    }
    this.FRoleList = lResult.resultData;
    if (this.FRoleList.length > 0) {
      if (this.$myStrHelper.stringIsEmpty(this.FRoleList[0].FRoleID)) {
        this.$myMsgHelp.msgDialog("返回的数据格式和前端的类定义不一至,请检查");
        return;
      }
    }
    this.zIsOpenData = true;
    this.$myMsgHelp.msgHintAutoClose(
      "获取数据成功",
      this.$myMsgHelp.msgSuccess
    );
  }
  //编辑界面回调列表事件
  private onCallBack(qAction: string, qCompany: TBaseRole) {
    if (qAction == "close") {
      this.FIsShowRole = false;
    }
    if (qAction == "save") {
      this.FIsShowRole = false;
      //重新刷新数据
      this.openData();
    }
  }
  //增加结构类型
  private onAdd() {
    this.FIndexRole = new TBaseRole();
    this.FIsShowRole = true;
  }
  private onEdit(qIndex: number, qRole: TBaseRole) {
    this.FIndexRole = qRole;
    this.FIsShowRole = true;
  }
  private onRightEdit(qIndex: number, qRole: TBaseRole) {
    this.FIndexRole = qRole;
    let lTag: IMenuItem = {
      menuIndexName: "RoleRightEdit_" + qRole.FRoleID,
      menuComponent: "TFormRoleRightEdit", //挂载的组件
      menuTitle: "【" + qRole.FRoleName + "】权限编辑", //标题
      menuIcon: "",
      menuParams: qRole,
      menuChildren: [], //子菜单
    };
    this.$myEvenBus.addTag(lTag);
  }
  private async initRoleRight() {
    let lResult = await this.$myBaseRightAPI.InitRoleRight();
    if (!lResult.resultSuccess) {
      this.$myMsgHelp.msgDialog(lResult.resultMsg);
      return;
    }
    this.$myMsgHelp.msgHintAutoClose("刷新中间件角色权限配置成功");
  }
}
</script>